<include file="Common/common" />

<body>
	
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<br>
			<form class="layui-form" id="keytask-form" action="">
				<div class="layui-form-item">
					<div class="layui-form-mid layui-word-aux"><span style="color: rgb(240,222,112)">您当前的动态秘钥:</span><span style="color: red;" >{$userInfo['key_dynamic']}</span><span style="color: rgb(240,222,112)">,任务秘钥:</span><span style="color: red;" >{$userInfo['key_task']}</span></div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="color: rgb(240,222,112)">转换数量</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="number" id="num" name="num" lay-verify="required" min="0" step="0.1"  onkeyup="checknum(this);" autocomplete="off"  class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block" style="margin-left: 105px;">
						<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" lay-submit="" lay-filter="btn-keytask">确定</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
<script type="text/javascript">
	// 验证数字
   	function checknum(obj){   
     	if(/^\d+\.?\d{0,1}$/.test(obj.value)){
        	obj.value = obj.value;
     	}else{
        	obj.value = obj.value.substring(0,obj.value.length-1);
     	}     
   	}

   	var maxkey = {$userInfo['key_dynamic']};

   	layui.use(['form','layer','jquery'], function () {
     
        // 操作对象
        var form = layui.form;
        var $ = layui.jquery;

        // 动态秘钥转任务秘钥
		form.on('submit(btn-keytask)',function (data) {
			if (data.field.num.trim() > maxkey ) {
                layer.msg('<span style="color: rgb(240,222,112);">动态秘钥不足</span>');
				return false;
			}else{
				if (data.field.num.trim() <= 0 || data.field.num.trim() == '') {
                    layer.msg('<span style="color: rgb(240,222,112);">数量不能为空</span>');
					return false;
				}else{
					layer.confirm('确定转换？',{offset:'none'},function(index){
						$.ajax({
				            type: "post",
				            url: "{:U('Coin/ctrl_keytask')}",
				            data: data.field,
				            dataType: "json",
				            success: function(rtJson){
				            	if (rtJson.code == 1) {
				            		$('#keytask-form')[0].reset();//重置表单
                                    layer.msg('<span style="color: rgb(240,222,112);">'+ rtJson.msg+'</span>');
					               	setTimeout(function(){location.reload();}, 1000);
				               	}else{
                                    layer.msg('<span style="color: rgb(240,222,112);">'+ rtJson.msg+'</span>');
				               	}
				            }
				        });
					});
				}
			}
			return false;
		});
    });
</script>
<include file="Common/footer" />